home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / hiddenfu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  3.5 KB  |  121 lines

  1. /*
  2.                              H I D D E N F U . C
  3. */
  4.  
  5.  
  6. #include "iccomp.h"
  7.  
  8. static int next_call()
  9. {
  10.     register int
  11.         opcode;
  12.  
  13.     switch (opcode = getopcode(s_bin))
  14.     {
  15.         case op_push_imm:
  16.         case op_jmp:
  17.         case op_jmp_false:
  18.         case op_jmp_true:
  19.         case op_push_strconst:
  20.         case op_push_var:
  21.         case op_pop_var:
  22.         case op_copy_var:
  23.         case op_inc:
  24.         case op_dec:
  25.             fseek(s_bin, sizeof(INT16), SEEK_CUR);
  26.         return (0);                         /* close, but no cigar */
  27.  
  28.         case op_push_1_jmp_end:
  29.         case op_call_rss:
  30.         case op_asp:
  31.             fseek(s_bin, sizeof(char), SEEK_CUR);
  32.         return (0);                         /* close, but no cigar */
  33.  
  34.         case op_push_0:
  35.         case op_push_reg:
  36.         case op_umin:
  37.         case op_atoi:
  38.         case op_itoa:
  39.         case op_atol:
  40.         case op_mul:
  41.         case op_div:
  42.         case op_mod:
  43.         case op_add:
  44.         case op_sub:
  45.         case op_eq:
  46.         case op_neq:
  47.         case op_sm:
  48.         case op_gr:
  49.         case op_younger:
  50.         case op_older:
  51.         case op_smeq:
  52.         case op_greq:
  53.         case op_exit:
  54.         case op_ret:
  55.         case op_band:
  56.         case op_bor:
  57.         case op_bnot:
  58.         case op_xor:
  59.         case op_shl:
  60.         case op_shr:
  61.         case op_pop_reg:
  62.                                             /* no argument with opcodes */
  63.         return (0);                         /* close, but no cigar */
  64.  
  65.         case op_call:
  66.         return (1);                         /* cigar! check this argument */
  67.  
  68.         case op_frame:                  /* next byte: # bytes to skip */
  69.             fseek(s_bin, getopcode(s_bin), SEEK_CUR);
  70.         return (0);                         /* close, but no cigar */
  71.  
  72.         default:
  73.             printf("\n"
  74.                   "at offset 0x%lx: @#$%%!!\n"
  75.                   "*INTERNAL ICM-COMP COMPILER ERROR*\n"
  76.                   "In function hidden_functions(): unrecognized opcode while\n"
  77.                   "patching up (hidden-)function calls.\n"
  78.                   "Found opcode: 0x%x.\n"
  79.                   "Please inform the ICCE ICMAKE (Z-side) support group\n"
  80.                   "\n"
  81.                   "THE BIM-FILE IS INVALID AND SHOULD *NOT* BE USED\n"
  82.                   , ftell(s_bin)
  83.                   , opcode
  84.                   );
  85.     }
  86.  
  87.     return (0);
  88. }
  89.  
  90. void hidden_functions()
  91. {
  92.     long
  93.         eof;
  94.     register int
  95.         fun;
  96.  
  97.     if (!hidden_called)
  98.         return;                             /* no hidden calls: nothing to do */
  99.  
  100.     eof = ftell(s_bin);                     /* remember the eof position */
  101.                                             /* go to begin of code */
  102.     fseek(s_bin, sizeof(BIN_HEADER_), SEEK_SET);
  103.  
  104.     while (ftell(s_bin) < eof)              /* continue until code processed */
  105.     {
  106.         if (next_call())                    /* find function call */
  107.         {
  108.             fun = -getint16(s_bin);         /* get the address (toggled sign) */
  109.             if (fun >= 0)                   /* hidden function */
  110.             {                               /* reset to patchup */
  111.                 fseek(s_bin, -(long)sizeof(INT16), SEEK_CUR);
  112.                 strcpy(string, hidden[fun].name);
  113.                                             /* update the function's address */
  114.                 outbin(&(funtab.symbol[fetchfun()].var.vu.i->count),
  115.                          sizeof(INT16));
  116.                 fseek(s_bin, 0, SEEK_CUR);  /* ready to read again */
  117.             }
  118.         }
  119.     }
  120. }
  121.